package com.kalle.workflow.query;

import com.kalle.workflow.elements.Flow;
import com.kalle.workflow.enums.FlowStatus;
import com.kalle.workflow.mapper.FlowMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FlowQuery extends AbstractQuery<Flow> {

    private final FlowMapper flowMapper;

    private final Map<String, Object> conditionMap;

    public FlowQuery(FlowMapper flowMapper) {
        this.flowMapper = flowMapper;
        this.conditionMap = new HashMap<>();
    }

    public FlowQuery deploymentId(String deploymentId) {
        conditionMap.put("deploymentId", deploymentId);
        return this;
    }

    public FlowQuery processKey(String processKey) {
        conditionMap.put("processKey", processKey);
        return this;
    }

    public FlowQuery processId(String processId) {
        conditionMap.put("processId", processId);
        return this;
    }

    public FlowQuery taskId(String taskId) {
        conditionMap.put("taskId", taskId);
        return this;
    }

    public FlowQuery active() {
        conditionMap.put("flowStatus", FlowStatus.ACTIVE.name());
        return this;
    }

    @Override
    List<Flow> list() {
        return flowMapper.list(conditionMap);
    }

}
